package com.stars.questions.deptQuestion.config.controller;

import com.alibaba.druid.util.StringUtils;
import com.stars.base.entity.Result;
import com.stars.questions.deptQuestion.config.entity.DeptConfigDTO;
import com.stars.questions.deptQuestion.config.entity.Organizes;
import com.stars.questions.deptQuestion.config.service.DeptService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : Rocks
 * @version : 1.0
 * @date : 2022/10/1 23:16
 * @description : 部门维护控制器
 */
@RestController
@RequestMapping("/deptConfig")
public class DeptConfigController {

    private final DeptService deptService;

    public DeptConfigController(DeptService deptService) {
        this.deptService = deptService;
    }

    /**
     * 根据查询条件获取调查部门列表
     * @author : Rocks
     * @date :  2023/2/26 21:46
     * @param dto 查询条件
     * @return Result
     */
    @RequestMapping("/getOrganizesList")
    public Result getOrganizesList(@RequestBody DeptConfigDTO dto){
        return Result.success(deptService.getOrganizesList(dto));
    }

    /**
     * 根据调查部门ID获取部门信息
     * @author : Rocks
     * @date :  2023/2/26 21:47
     * @param id 调查部门ID
     * @return Result
     */
    @RequestMapping("/getOrganizeById")
    public Result getOrganizeById(String id){
        return Result.success(deptService.getOrganizesData(id));
    }

    /**
     * 保存调查部门
     * @author : Rocks
     * @date :  2023/2/26 21:47
     * @param org 要保存的部门对象
     * @return Result
     */
    @RequestMapping("/save")
    public Result save(@RequestBody Organizes org){
        return Result.result(deptService.saveOrUpdate(org));
    }

    /**
     * 删除调查部门
     * @author : Rocks
     * @date :  2023/2/26 21:47
     * @param id 要删除的调查部门ID
     * @return Result
     */
    @RequestMapping("/remove")
    public Result remove(String id){

        if(StringUtils.isEmpty(id)){
            return Result.error("删除失败");
        }
        return Result.result(deptService.deleteData(id));
    }

    /**
     * 获取调查部门最大排序
     * @author : Rocks
     * @date :  2023/2/26 21:48
     * @return Result
     */
    @RequestMapping("/getMaxOrder")
    public Result getMaxOrder(){
        return Result.success(deptService.getDeptMaxOrder());
    }
}
